package com.dries.security.core.validate.code.captcha.sms;

import com.dries.security.core.properties.SecurityCoreConstants;
import com.dries.security.core.validate.code.captcha.SysCaptcha;
import com.dries.security.core.validate.code.impl.AbstractValidateCodeProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;

/**
 * @Description: 生成短信验证码
 * @Author ZSY
 * @createTime 2020/9/7 16:55
 */
@Component("smsCaptcha")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<SysCaptcha> {


    @Resource
    private SmsCodeSender smsCodeSender;

    /**
     * 发送校验码，由子类实现
     *
     * @param request
     * @param sysCaptcha
     * @throws Exception
     */
    @Override
    protected void send(ServletWebRequest request, SysCaptcha sysCaptcha) throws Exception {
        String paramName = SecurityCoreConstants.DEFAULT_PARAMETER_NAME_MOBILE;
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), paramName);
        smsCodeSender.send(mobile, sysCaptcha.getCode());
    }

}
